<template>
  <div class="auth-page">
    <header class="auth-header">
      <div class="sys-title">
        <span class="title-zh">Dyform-动态表单</span>&nbsp;
      </div>
    </header>
    <div class="auth-content">
      <div class="login-page">
        <div class="login-form" id="login-form">
          <el-form
            :model="dataForm"
            class="animated fadeInRight"
            :rules="dataRule"
            ref="dataForm"
            @keyup.enter.native="dataFormSubmit()"
            status-icon
          >
            <el-form-item prop="userNo">
              <el-input
                v-model="dataForm.userNo"
                size="medium"
                class="login-input"
                prefix-icon="el-icon-user"
                autocomplete="off"
                placeholder=" 请输入登录账号"
              >
              </el-input>
            </el-form-item>

            <el-form-item prop="password">
              <el-input
                v-model="dataForm.password"
                size="medium"
                class="login-input"
                prefix-icon="el-icon-key"
                type="password"
                autocomplete="off"
                placeholder=" 请输入登录密码"
              ></el-input>
            </el-form-item>

            <el-form-item prop="captcha">
              <el-input
                type="text"
                size="medium"
                class="login-captcha"
                prefix-icon="el-icon-view"
                v-model="dataForm.captcha"
                placeholder="请输入验证码"
              ></el-input>
              <img
                alt="换一张"
                :src="captchaPath"
                id="validaId"
                style="height:34px;width:130px;cursor:pointer;margin-top:0px;margin-left: 3px;"
                @click="getCaptcha()"
              />
            </el-form-item>
            <div v-loading="logining" class="login-item-center">
              <el-button
                size="medium"
                :loading="logining"
                class="login-button"
                name="submit"
                type="primary"
                @click="dataFormSubmit()"
                >{{ logining ? "正在登录..." : "登   录" }}</el-button
              >
            </div>
          </el-form>
        </div>
      </div>
      <div class="auth-footer">
        <!--  <el-divider></el-divider> -->
        Copyright © 2021 雪浪云 All rights reserved 苏ICP备 18034176号-1
      </div>
    </div>
    <!---->
  </div>
</template>
<script>
import { getUUID } from "@/utils/index";
import { encryptDes } from "@/utils/des";
import { login ,getCaptchaUrl } from '@/api/sys/user'
export default {
  data() {
    return {
      dataForm: {
        userNo: "",
        password: "",
        uuid: "",
        captcha: ""
      },
      dataRule: {
        userNo: [
          { required: true, message: "登录账号不能为空", trigger: "blur" }
        ],
        password: [
          { required: true, message: "登录密码不能为空", trigger: "blur" }
        ],
        captcha: [
          { required: true, message: "验证码不能为空", trigger: "blur" }
        ]
      },
      captchaPath: "",
      logining: false
    };
  },
  created() {
    this.getCaptcha();
  },
  methods: {
    // 提交表单
    dataFormSubmit() { 
      this.$refs["dataForm"].validate(valid => {
        if (valid) {
          this.logining = true;
          // 加密密码
          const pass = encryptDes(this.dataForm.password);
        
          login(this.dataForm.userNo.trim() , pass , this.dataForm.uuid , this.dataForm.captcha.trim()).then(({ data }) => {
              if (data && data.code === 0) {
                this.$cookie.set("token", data.data.token);
                this.$router.replace({ name: "home" }).catch(e2=>{
                   
                });
              } else {
                this.getCaptcha();
                this.dataForm.captcha = "";
                this.$message.error(data.msg);
              }
            })
            .catch(err => {
              this.$message.error(err);
            })
            .finally(() => {
              this.logining = false;
            });
        }
      });
    },

    // 获取验证码
    getCaptcha() {
      this.dataForm.uuid = getUUID();
      this.captchaPath = getCaptchaUrl(this.dataForm.uuid)  
       
    }
  }
};
</script>
<style lang="scss" scoped>
.auth-page {
  display: -webkit-box;
  display: -ms-flexbox;
  display: flex;
  -webkit-box-orient: vertical;
  -webkit-box-direction: normal;
  -ms-flex-direction: column;
  flex-direction: column;
  width: 100%;
  height: 100%;
  position: absolute;
  background-color: #f0f2f5;

  .auth-header {
    padding: 0 60px;
    height: 70px;
    line-height: 70px;
    background-color:  #094884; /* #094884 */

    .sys-title {
      display: inline-block;
      height: 100%;
      padding-left: 100px;
      font-weight: 600;
      color: #fff;
      cursor: pointer;
      background-repeat: no-repeat;
      background-position: 5px;
      background-size: 22%;

      .title-zh {
        font-size: 30px;
        opacity: 1;
        font-family: "Microsoft YaHei";
        letter-spacing: 4px;
      }

      .title-en {
        font-size: 12px;
        opacity: 0.5;
      }
    }
  }

  .auth-content {
    width: 1200px;
    margin: 0 auto;
    min-height: 500px;
    display: -webkit-box;
    display: -ms-flexbox;
    display: flex;
    -webkit-box-flex: 1;
    -ms-flex: 1;
    flex: 1;
    -webkit-box-orient: vertical;
    -webkit-box-direction: normal;
    -ms-flex-direction: column;
    flex-direction: column;
    -webkit-box-pack: justify;
    -ms-flex-pack: justify;
    justify-content: space-between;

    .login-page {
      position: relative;
      height: 100%;
      background: url(~@/assets/img/bg2.png) no-repeat 0;
      display: -webkit-box;
      display: -ms-flexbox;
      display: flex;
      -webkit-box-flex: 1;
      -ms-flex: auto;
      flex: auto;
      -webkit-box-align: center;
      -ms-flex-align: center;
      align-items: center;
      -webkit-box-pack: end;
      -ms-flex-pack: end;
      justify-content: flex-end;

      .login-form {
        width: 430px;
        padding: 50px;
        border: 1px solid #085fb1;
        /*background-color: #085fb152;*/
        /*box-shadow: 10px 10px 5px #888888;*/
        border-radius: 5px;
        input {
          height: 47px;
        }

        .login-form-header {
          text-align: center;
          margin-top: 5rem;
        }

        .login-item-center {
          text-align: center;

          .login-button {
            background-color:  #094884; /* #094884 */
            border-color: #094884;
          }
        }
        .login-item-center button {
          width: 100%;
        }
        .login-captcha {
          width: 58%;
        }
      }
    }
  }

  .auth-footer {
    text-align: center;
    /*color: #888;*/
    font-size: 13px;
    margin-bottom: 10px;
    line-height: 2;

    .footer-menu {
      display: -webkit-box;
      display: -ms-flexbox;
      display: flex;
      -webkit-box-pack: center;
      -ms-flex-pack: center;
      justify-content: center;

      div {
        padding: 0 20px;

        a {
          color: #888;
        }
      }
    }
  }
}

@media screen and (max-width: 768px) {
  .login-page {
    background: none;
  }
}
</style>
